package com.zxy.hotel.controller;


import com.zxy.hotel.entity.RS;
import com.zxy.hotel.entity.Vip;
import com.zxy.hotel.service.VipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author jiusi
 * @since 2021-12-12
 */
@RestController
@RequestMapping("/vip")
@PreAuthorize("hasAnyRole('admin','root','staff')")
public class VipController {
    @Autowired
    private VipService vipService;

    @GetMapping
    public RS queryVip(String cardId) {
        if (!StringUtils.hasText(cardId)) {
            return RS.fail().message("请输入内容");
        }
        List<Vip> list = vipService.fuzzy(cardId);
        return RS.ok().data(list);
    }

    @PostMapping
    public RS registerVip(String name, String cardId, String phone) {
        if (!StringUtils.hasText(name) || !StringUtils.hasText(cardId) || !StringUtils.hasText(phone)) {
            return RS.fail().message("请填写完整的信息");
        }
        Integer i = vipService.register(name, cardId, phone);
        return RS.ok().data(i);
    }
}
